﻿package smooth.core.canvas.multimediaCanvas {
	import app.core.element.Wrapper;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import smooth.core.canvas.liquidCanvas.LiquidCanvas;
	import flash.events.*;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.AntiAliasType;
	import caurina.transitions.Tweener;	
	
	
	public class MultimediaCanvas extends LiquidCanvas {
		
		[Embed(source="Arial.ttf", fontFamily="myFont")] 
		public var myFont:Class;
		// START - 20081129 - LSA
		//private var multimediaObjects:Array = new Array();
		public var multimediaObjects:Array = new Array();
		// END - 20081129 - LSA
		private var initialLabel:String;
		// START - 20081129 - LSA
		//private var arrangeIndex:int = 0;
		// END - 20081129 - LSA
		
		public function MultimediaCanvas(label:String, posX:int, posY:int, sizeX:int, sizeY:int, color:int) {
			// Init des attributs de l'objet
			this.initialLabel = label;
			// Appel du constructeur de la classe parente
			super(posX, posY, sizeX, sizeY, color);
			// Init des visuels du composant			
			initGraphics();
			// Init des events du composant
			initEvents();	
			// Init des process du composant
			initProcess();
		}
		
		private function initGraphics():void {
			// Formatage du libellé
			var formatLabel:TextFormat= new TextFormat();
			formatLabel.font= "myFont";
			formatLabel.color= 0xFFFFFF;
			formatLabel.size= 70;
			// Nom du composant
			var tLabel: TextField;
			tLabel = new TextField();
			tLabel.alpha = 0.7;
			tLabel.embedFonts = true;
			tLabel.selectable  = false;		 
			tLabel.text = initialLabel;
			tLabel.autoSize = TextFieldAutoSize.CENTER;
			tLabel.name = "tLabel";
			tLabel.x = (this.width - tLabel.width)/2;
			tLabel.y = (this.height - tLabel.height)/2;
			tLabel.visible = false;
			tLabel.setTextFormat(formatLabel);
			this.addChild(tLabel);
			// START - 20081129 - LSA
			// Add changeDisplayButton to canvas menu
			this.menu.addButton(new ChangeDisplayComponent(this));
			// END - 20081129 - LSA
		}
		
		private function initProcess():void {
		}
		
		private function initEvents():void {
			this.addEventListener(TouchEvent.MOUSE_DOWN, this.touchDown);						
			this.addEventListener(TouchEvent.MOUSE_UP, this.touchUp);	
		}
		
		public function doInitLabel(label:String):void {
			trace("MultimediaCanvas::sprialPhotos");
			var formatLabel:TextFormat= new TextFormat();
			formatLabel.font= "myFont";
			formatLabel.color= 0xFFFFFF;
			formatLabel.size = 70;
			var tLabel:TextField = this.getChildByName("tLabel") as TextField
			tLabel.text = label;
			tLabel.visible = true;
			tLabel.setTextFormat(formatLabel);
		}
		
		private function touchDown(e:TouchEvent):void {
			// Formatage du libellé
			var formatLabel:TextFormat= new TextFormat();
			formatLabel.font= "myFont";
			formatLabel.color= 0xFFFFFF;
			formatLabel.size = 70;
			// Récupération du libellé
			var tLabel:TextField = this.getChildByName("tLabel") as TextField;
			// Passage au premier plan
			this.addChildAt(tLabel, this.numChildren);
			// Réaffectation du format d'origine
			tLabel.setTextFormat(formatLabel);
			// Marquage du libellé comme visible 
			tLabel.visible = true;
		}
		
		public function pushMultimediaObject(object:Object):void {
			this.multimediaObjects.push(object);
			this.addChild(object);
		}
		
		private function touchUp(e:TouchEvent):void {
			var tLabel:TextField = this.getChildByName("tLabel") as TextField;
			tLabel.visible = false;
		}
		
	}
	
}